import React,{Component} from'react';
import {
  Link
} from 'react-router-dom';
import { getAnnouncement } from 'api/home.js';
import './notice.scss';
export default class Notice extends Component{
	constructor(props){
    super(props)
    this.state = {
      noticeList:[]
    }
	}
	componentWillMount () {
		getAnnouncement({
			sort:this.props.location.state.current+1
		}).then(res => {
			if (res.code === 1) {
        this.setState({
         noticeList: res.data.data
        })
      }
		})
	}
	render(){
		return(
			<div className="notice">
				<Link to={
					{
						pathname: '/news',
						state: {current:this.props.location.state.current}
					}
				}><span className="glyphicon glyphicon-back back"></span></Link>
				<div className="news_title">
					{
						this.props.location.state.current===0 ?
						<span>公告</span>
						:
						<span>新闻</span>
					}
				</div>
				{
					this.state.noticeList.map((item,index) => {
						if( item.article_id === this.props.location.state.article_id ) {
							return(
								<div className="notice_content" key={index}>
									<div className="notice_title">{item.article_title}</div>
									<div className="notice_con" dangerouslySetInnerHTML={{__html: item.article_desc}}></div>
									<div className="notice_time">{item.article_add_time}</div>
								</div>
							)
						}
					})
				}
			</div>
		)
	}
}